package com.srcbox.file.fragment.pager

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.flyco.tablayout.SegmentTabLayout
import com.flyco.tablayout.listener.OnTabSelectListener
import com.srcbox.file.R
import com.srcbox.file.ui.Main
import com.srcbox.file.fragment.AppFilesGet
import com.srcbox.file.fragment.LocalFilesGet

class MainA() : Fragment() {
    private var v: View? = null
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val v = inflater.inflate(R.layout.main_nav_one, container, false)
        initView(v)
        return v
    }

    private fun initView(v: View) {
        this.v = View(context)
        val tabLay = v.findViewById<SegmentTabLayout>(R.id.tabLay)
        val fArr = ArrayList<Fragment>()
        val appFileGet = AppFilesGet()

        fArr.add(appFileGet)
        fArr.add(LocalFilesGet())
        tabLay.setTabData(arrayOf("应用", "本地"), activity, R.id.fragment_change, fArr)
        if (Main.Data.isALoad) {
            tabLay.currentTab = 1
        } else {
            tabLay.currentTab = 0
        }

        tabLay.setOnTabSelectListener(object : OnTabSelectListener {
            override fun onTabSelect(position: Int) {
                Main.Data.isALoad = position == 1
            }

            override fun onTabReselect(position: Int) {}
        })
    }
}